﻿namespace ManagerClinic.DanhMuc
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using DevExpress.XtraEditors;
    using ManagerClinic.Core.Common;
    using ManagerClinic.Core.Business;
    using ManagerClinic.Modules;
    using ManagerClinic.Ultilities.Ultility;

    public partial class frmDmGioiTinh : DevExpress.XtraEditors.XtraForm
    {
        IList<DmGioiTinhEntity> lstDmGioiTinhEntity = null;
        GridCheckMarksSelection gridCheckMarksSelection = null;
        DmGioiTinhBusiness dmGioiTinhBusiness = new DmGioiTinhBusiness();

        public frmDmGioiTinh()
        {
            InitializeComponent();
            gridCheckMarksSelection = new GridCheckMarksSelection(gvDmGioiTinh);
        }

        void LoadDMgioitinh(object sender, EventArgs e)
        {
            lstDmGioiTinhEntity = dmGioiTinhBusiness.GetDmGioiTinhList();
            grdDmGioiTinh.DataSource = lstDmGioiTinhEntity;
        }

        DmGioiTinhEntity GetRow()
        {
            if (gvDmGioiTinh.RowCount > 0)
                return (DmGioiTinhEntity)gvDmGioiTinh.GetFocusedRow();
            return null;
        }

        private void frmDMGioitinh_Load(object sender, EventArgs e)
        {
            Authenticate.IsAuthenticateForm(this);
            LoadDMgioitinh(sender, e);
        }

        private void btnThemMoi_Click(object sender, EventArgs e)
        {
            var frm = new frmCapNhatDmGioiTinh((int)ConstantManagerClinic.StateInsertOrUpdate.Insert);
            frm.dmGioiTinhEvent += new EventHandler(LoadDMgioitinh);
            frm.ShowDialog();
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            DmGioiTinhEntity dmGioiTinhEntity = GetRow();
            if (dmGioiTinhEntity == null) return;
            var frm = new frmCapNhatDmGioiTinh((int)ConstantManagerClinic.StateInsertOrUpdate.Update, dmGioiTinhEntity);
            frm.dmGioiTinhEvent += new EventHandler(LoadDMgioitinh);
            frm.ShowDialog();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            var deleteObjects = gridCheckMarksSelection.selection;
            if (deleteObjects.Count <= 0)
            {
                MessageBox.Show("Bạn chưa chọn bản ghi để xóa!", ConstantManagerClinic.sTitleInformation, MessageBoxButtons.OK);
                return;
            }

            if (MessageBox.Show("Bạn chắc chắn muốn xóa dữ liệu?", ConstantManagerClinic.sTitleWarming, MessageBoxButtons.YesNo) == DialogResult.No)
            {
                gridCheckMarksSelection.ClearSelection();
                return;
            }
            foreach (DmGioiTinhEntity item in deleteObjects)
            {
                dmGioiTinhBusiness.DeleteDmGioiTinh(item.MaGioiTinh);
            }
            gridCheckMarksSelection.ClearSelection();
            LoadDMgioitinh(sender, e);
        }

        private void gvDmgioitinh_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
                e.Handled = false;
            }
        }

        private void grdDmgioitinh_DoubleClick(object sender, EventArgs e)
        {
            if (btnSua.Enabled == false) return;
            if (gvDmGioiTinh.RowCount > 0)
                btnSua_Click(sender, e);
        }


    }
}